package 晚间作业0319;


import java.util.Arrays;

/**
 * 已知圆通快递可以发陆运，EMS可以发空运，顺丰快递既可以发空运，也可以发陆运。小明需要发送快递，
 * 设计两个方法，分别用来发空运和陆运。当对方收到包裹的时候，快递公司需要告诉发送方确认信息。(接口和内部类的实战案例一)
 * 2.1.使用接口实现基础功能
 * 2.2.匿名内部类优化代码
 */
public class Doc_Cus2 {
    public static void main(String[] args) {
        ReceiveCallback callback = () -> System.out.println("我知道了");
        Person person = new Person("小明");

        person.sendByAir(new EMS(), callback);
        person.sendByLand(new LandTranslation() {
            @Override
            public void land(ReceiveCallback callback) {
                System.out.println("其他快递公司陆运快递送到了");
                callback.onReceive();
            }
        }, callback);

        String hello = "      hello world     ";
//        hello = hello.trim();
//        System.out.println(hello);
        String[] split = hello.split("\\s+");
        System.out.println(split[1] + split[2]);

        String[] split1 = hello.split("");
        System.out.println(Arrays.toString(split1));
    }

    public static class Person {
        private String name;

        public Person(String name) {
            this.name = name;
        }

        public void sendByLand(LandTranslation landTranslation, ReceiveCallback callback) {
            landTranslation.land(callback);
        }

        public void sendByAir(AirTranslation airTranslation, ReceiveCallback callback) {
            airTranslation.air(callback);
        }
    }

    public interface AirTranslation { void air(ReceiveCallback callback); }
    public interface LandTranslation { void land(ReceiveCallback callback); }
    public interface ReceiveCallback { void onReceive(); }

    public static class Company {
        protected String cName;

        public Company(String cName) {
            this.cName = cName;
        }
    }

    public static class YT extends Company implements LandTranslation {
        public YT() { super("圆通"); }

        @Override
        public void land(ReceiveCallback callback) {
            System.out.println(cName + "陆运送快递送到了");
            callback.onReceive();
        }
    }

    public static class EMS extends Company implements AirTranslation {
        public EMS() {super("EMS");}

        @Override
        public void air(ReceiveCallback callback) {
            System.out.println(cName + "空运送快递送到了");
            callback.onReceive();
        }
    }

    public static class SF extends Company implements AirTranslation, LandTranslation {
        public SF() {
            super("顺丰");
        }

        @Override
        public void air(ReceiveCallback callback) {
            System.out.println(cName + "空运送快递送到了");
            callback.onReceive();
        }

        @Override
        public void land(ReceiveCallback callback) {
            System.out.println(cName + "陆运送快递送到了");
            callback.onReceive();
        }
    }
}
